package ua.vn.ticket_scanner.network.data;

import org.json.JSONException;
import org.json.JSONObject;

import java.util.HashMap;

/**
 * Created by Ivan on 17.06.13.
 */
public class ConnectResult {

    public static final HashMap<String, String> errorCodes = new HashMap<String, String>();

    static {
        errorCodes.put("0", "0.No generated key (used for MD5)");
        errorCodes.put("1", "1.Bad secret key");
        errorCodes.put("2", "2.Transport_id not found");
        errorCodes.put("3", "3.Ticket not found in database");
        errorCodes.put("4", "4.There is ticket in a black list");
        errorCodes.put("5", "5.Over the number of trips");
        errorCodes.put("6", "6.Expired use");
        errorCodes.put("7", "7.Ticket is not suitable for this route");
        errorCodes.put("8", "8.Ticket isn't active");
        errorCodes.put("9", "9.Ticket is not suitable for this transport");
        errorCodes.put("10", "10.Invalid command");
        errorCodes.put("11", "11.Invalid command format");
        errorCodes.put("12", "12.Unknown code");
    }

    private JSONObject json = null;

    public void setJSON(JSONObject json) {
        this.json = json;
    }

    public String get(String key) {
        if (json != null) {
            try {
                return json.getString(key);
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }
        return null;
    }
}
